<!--
 * @Author: liwei 474083297@qq.com
 * @Date: 2024-05-18 19:09:59
 * @LastEditors: liwei 474083297@qq.com
 * @LastEditTime: 2024-05-21 15:22:57
 * @FilePath: /app/src/authLogsHome.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
	<div class="authLogs-container">
		<el-table
			:data="logs"
			stripe
			border
			highlight-current-row
			:default-sort="{ prop: 'eventTime', order: 'descending' }"
			style="width: 100%"
		>
			<el-table-column type="index" label="序号" width="90" align="center" />
			<el-table-column prop="id" label="id" width="80" align="center">
			</el-table-column>
			<el-table-column
				sortable
				prop="eventTime"
				label="时间"
				width="230"
				align="center"
			>
			</el-table-column>
			<el-table-column
				prop="operateusername"
				label="授权人员"
				sortable
				width="150"
				align="center"
			>
			</el-table-column>
			<el-table-column
				prop="targetusername"
				label="被授权人员"
				sortable
				width="150"
				align="center"
			>
			</el-table-column>
			<el-table-column prop="targetuserid" label="被授权人员ID" align="center">
			</el-table-column>
			<el-table-column
				prop="detail"
				show-overflow-tooltip
				min-width="250"
				label="授权详细信息"
				align="center"
			>
			</el-table-column>
		</el-table>
	</div>
</template>

<script>
import axios from 'axios';
// import moment from 'moment.js';
export default {
	name: 'AppAuthLogsHome',

	data() {
		return {
			logs: []
		};
	},
	mounted() {
		this.requestLogs();
	},

	methods: {
		requestLogs() {
			axios
				.get('/tjDemo/auth/getAuthLogs')
				.then(response => {
					let data = response.data || '';
					this.logs = data;

					data.forEach(element => {
						let nodeChain = '';
						let infos = JSON.parse(element.accessiblenodeinfo);
						// console.log('infosinfos---', infos);
						infos?.forEach(e => {
							nodeChain = nodeChain + '-' + e.name;
						});

						element.eventTime = this.$moment(element.eventTime).format(
							'YYYY-MM-DD HH:mm:ss'
						);
						element.detail =
							element.operateusername +
							' 于' +
							element.eventTime +
							' 给' +
							element.targetusername +
							' 进行了授权操作，使' +
							element.targetusername +
							' 拥有了对' +
							nodeChain +
							' 下的人员有可见的权限';
					});

					console.log('获取授权列表--', data);
				})
				.catch(error => {
					console.error(error);
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.authLogs-container {
	padding: 0;
	margin: 0;
	// width: 100%;
	height: calc(100vh - 70px);
	background-color: rgb(246, 246, 246);
	padding: 40px;
}
</style>
